/****
 * Copyright (C) 2006 dNux
 *                                                            ****
 * This program is free software; you can redistribute it and/or *
 * modify under the terms of the GNU General Public License as   *
 * published by the Free Software Foundation;                    *
 * either version 2 of the License.                              *
 *                                                               *
 * This program is distributed in the hope that it will be       *
 * useful, but WITHOUT ANY WARRANTY; without even the implied    *
 * warranty of without even the implied waranty of               *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.          *
 * See the GNU General Public License for more details.          *
 *                                                               *
 * You should have received a copy of the                        *
 * GNU General Public License                                    *
 * along with this program; if not, write to the                 *
 * Free Software Foundation, Inc.,                               *
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. *
 *                                                               *
 ****                                                         ****/

#include "dcore.h"

char **
d_argv_new()
{
  char **argv=NULL;
  argv = (char **) malloc(sizeof(char *));
  if (argv) {
    argv[0]=NULL;
  }
  return argv;
}

void
d_argv_free(char ***argv)
{
  free(*argv);
  *argv = NULL;
}

void
d_argv_add(char ***argv, char *arg)
{
  int len;
  char **new=NULL;

  len = d_argv_length(*argv);
  new = (char **) realloc(*argv, sizeof(char *) * ( len + 2));
  if (new) {
    new[len] = arg;
    new[len+1] = NULL;
    *argv = new;
  }
}

int
d_argv_length(char **argv)
{
  int i;
  for (i=0; argv[i]; i++);
  return i;
}
